//01folktale 中的 compose curry
const { compose, curry } = require("folktale/core/lambda");
const { toUpper, first, split, find } = require("lodash/fp");
let f = curry(2, (x, y) => {
  return x + y;
});
console.log(f(1, 2));
let fn = compose(toUpper, first);
console.log(fn(["one", "two"]));

//02folktale 中的 Task 函子中的异步函数
const fs = require("fs");
const { task } = require("folktale/concurrency/task");
function redFile(fileName) {
  return task((resolver) => {
    fs.readFile(fileName, "utf-8", (err, data) => {
      if (err) resolver.reject(err);
      resolver.resolve(data);
    });
  });
}
redFile("package.json")
  .map(split("\n"))
  .map(find((x) => x.includes("version")))
  .run()
  .listen({
    onRejected: (err) => {
      console.log(err);
    },
    onResolved: (v) => {
      console.log(v);
    },
  });
